#include <iostream>
#include <cmath>
using namespace std;

int map[8][8];
int statics[8][8];
int N, M, T;
int start[2], door[2];
bool found;

void dfs(int i2, int j2, int time)
{
    if(i2 == door[0] && j2 == door[1])
    {
        found = true;
        return;
    }
    int min_time = T - time -abs((door[0]-i2)) - abs((door[1] - j2));
    if(min_time <0 || min_time % 2 == 1)
    {
        return;
    }

}

int main()
{
    ios::sync_with_stdio(false);
    char tmp_char;
    while (cin >> N >> M >> T)
    {
        found = false;
        for (int i = 1; i <= N; i++)
        {
            for (int j = 1; j <= M; j++)
            {
                cin >> tmp_char;
                if (tmp_char == 'S')
                {
                    start[0] = i;
                    start[1] = j;
                }
                else if (tmp_char == 'D')
                {
                    door[0] = i;
                    door[j] = j;
                }
                if (tmp_char != 'X')
                {
                    map[i][j] = 0; // mark as 0 if is wall
                }
                else
                {
                    map[i][j] = 1; // mark as 1 if is road
                }
                statics[i][j] = 0;
            }
        }
    }
}